# from db.common import cli
#
#
#
# def read_report_sent_impl(start_time,end_time,project_id,department_id,title_match,login_name):
#     if start_time!= None and start_time!='' and end_time!= None and end_time!='':
#         str_time = "and Date(date_time) between '%s' and '%s' "%tuple([start_time,end_time])
#     else:
#         str_time = ""
#     if project_id != None and project_id!='' :
#         sql_project_name = "select project_name from project where project_id = '%s'"%project_id
#         project_name = cli.fetchall(sql_project_name)[0]['project_name']
#         str_project = "and project = '%s'"%project_name
#
#     else:
#         str_project = ""
#     if department_id != None and department_id!='' :
#         sql_department_name = "select department from department where deartment_id = '%s'" % department_id
#         department_name = cli.fetchall(sql_department_name)[0]['department']
#         str_department = "and department = '%s'" % department_name
#     else:
#         str_department = ""
#     if title_match!= None and title_match!='':
#         dim_title = '%'+title_match+'%'
#         str_title = "and title like '%s' "%dim_title
#     else:
#         str_title = ""
#     sql = "select * from logs where author = '%s'"%login_name +str_time+str_project+str_department+str_title
#     print(sql)
#     return cli.fetchall(sql)
#
#
#
#
# def read_Report_by_Id_Impl(login_name,log_id):
#
#     # 1.更新对自己发送的日报信息的已读状态。
#     sql_if_read ="select receiver,if_read from logs where log_id = '%s'"%log_id
#     res = cli.fetchall(sql_if_read)[0]
#     str_if_read = update_if_read(res['receiver'],res['if_read'],login_name)
#     sql_update_if_read = "update logs set if_read = '%s' where log_id = '%s'"%tuple([str_if_read,log_id])
#     cli.execute(sql_update_if_read)
#     sql = "select * from logs where log_id = {0[0]}".format([log_id])
#     print(sql)
#     return cli.fetchall(sql)
#
# def read_Report_by_Id_receiver_Impl(login_name,log_id):
#
#     # 1.更新对自己发送的日报信息的已读状态。
#     sql_if_read ="select receiver,if_read from logs where log_id = '%s'"%log_id
#     res = cli.fetchall(sql_if_read)[0]
#     str_if_read = update_if_read(res['receiver'],res['if_read'],login_name)
#     sql_update_if_read = "update logs set if_read = '%s' where log_id = '%s'"%tuple([str_if_read,log_id])
#     cli.execute(sql_update_if_read)
#     sql = "select * from logs where log_id = {0[0]}".format([log_id])
#     print(sql)
#     return cli.fetchall(sql)
#
# def read_report_receiver_impl(start_time,end_time,project_id,department_id,title_match,login_name):
#     if start_time!= None and start_time!='' and end_time!= None and end_time!='':
#         str_time = "and Date(date_time) between '%s' and '%s' "%tuple([start_time,end_time])
#     else:
#         str_time = ""
#     if project_id != None and project_id!='' :
#         sql_project_name = "select project_name from project where project_id = '%s'"%project_id
#         project_name = cli.fetchall(sql_project_name)[0]['project_name']
#         str_project = "and project = '%s'"%project_name
#
#     else:
#         str_project = ""
#     if department_id != None and department_id!='' :
#         sql_department_name = "select department from department where deartment_id = '%s'" % department_id
#         department_name = cli.fetchall(sql_department_name)[0]['department']
#         str_department = "and department = '%s'" % department_name
#     else:
#         str_department = ""
#     if title_match!= None and title_match!='':
#         dim_title = '%'+title_match+'%'
#         str_title = "and title like '%s' "%dim_title
#     else:
#         str_title = ""
#     dim_user = '%'+login_name+'%'
#     sql = "select * from logs where receiver like '%s'"%dim_user +str_time+str_project+str_department+str_title
#     print(sql)
#     return cli.fetchall(sql)
#
#
# def uniform_report_data(res):
#     for i in res:
#         # 返回时间标签
#         timeline={}
#         time_elements=i['date_time'].split('-')
#         timeline['year']=time_elements[0]
#         timeline['month']=time_elements[1]
#         timeline['day'] = time_elements[2]
#         timeline['hour'] = time_elements[3]
#         timeline['min'] = time_elements[4]
#         timeline['sec'] = time_elements[5]
#         i['timeline']= timeline
#         i.pop('date_time')
#         # 返回日报信息
#         todaylist = i['today_work'].split('/*/*/')
#         tomolist = i['tomorrow_work'].split('/*/*/')
#         unfinilist = i['remain_todo'].split('/*/*/')
#         article = {}
#         article['todaylist'] = todaylist
#         article['tomolist'] = tomolist
#         article['unfinilist'] = unfinilist
#         i['article'] = article
#         i.pop('today_work')
#         i.pop('tomorrow_work')
#         i.pop('remain_todo')
#     return res
#
# def update_if_read(receiver,if_read,login_name):
#     receiver_list = receiver.split(';')
#     if_read_list = if_read.split(';')
#     if len(receiver_list) != len(if_read_list):
#         return None
#     else:
#         str_if_read_new = ''
#         for i in range(len(receiver_list)):
#             if receiver_list[i] == login_name:
#                 str_if_read_new += '1'
#             else:
#                 str_if_read_new += if_read_list[i]
#             if i != len(receiver_list)-1:
#                 str_if_read_new += ';'
#     return str_if_read_new
#
#
#
#
#
#
#
